package com.zjs.express.dao.impl;

import com.zjs.express.bean.vo.UserCountVo;
import com.zjs.express.dao.UserDao;
import com.zjs.express.utils.DBUtils;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl extends DBUtils implements UserDao {
    @Override
    public UserCountVo statistics() {
        String sql = "select count(type=0 or null) as userTotalCount, count(to_days(create_time)=to_days(now()) and type=0 or null) as userDayRegCount, count(type=1 or null) as courierTotalCount, count(to_days(create_time)=to_days(now()) and type=1 or null) as courierDayRegCount from user";
        try {
            ResultSet resultSet = query(sql, null);
            while (resultSet.next()) {
                return new UserCountVo(resultSet.getInt("userTotalCount"), resultSet.getInt("userDayRegCount"), resultSet.getInt("courierTotalCount"), resultSet.getInt("courierDayRegCount"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll();
        }
        return null;
    }
}
